#pragma once

#include "Game/Process/RenderProcess.h"
#include "Render/Texture/Picture2DTexture.h"
#include "Render/Texture/RenderTarget.h"
#include "Render/Tradition/RHIRenderPass.h"
#include "Render/Tradition/GraphicsPipeline.h"
#include "Render/Texture/ColorRenderTarget.h"
#include "Render/Texture/CubemapTexture.h"
#include "Render/Texture/DepthRenderTarget.h"
#include "Render/Shader/RHIDescriptor.h"
#include "Render/Tradition/RHIFramebuffer.h"
#include "LocalEntity.h"
#include "LocalShader.h"
#include "Render/Raytracing/RayTracingPipeline.h"
#include "Render/Raytracing/TopLevelAccelerationStructure.h"


class RayTracingProcess : public RenderProcess
{
	DECLARE_PROCESS(RayTracingProcess)

	struct Ubo
	{
		glm::mat4 viewProj;       // Camera view * projection
		glm::mat4 viewInverse;    // Camera inverse view matrix
		glm::mat4 projInverse;    // Camera inverse projection matrix
		int32 frame;
		int32 maxFrame;
		int32 debugMode;
	};

public:

	int32 mDebugMode;

	int32 mFrame;

	int32 mMaxFrame;

protected:

	virtual void OnInit() override;

	virtual void OnTick(float deltaTime) override;

	virtual void OnResize() override;

protected:

	glm::mat4 mLastView;

	glm::mat4 mLastProj;

	std::vector<LocalEntity*> mLocalEntitys;

	std::vector<ObjDescGpu> mObjDescs;

	RefCountPtr<RHIBuffer> mObjDescBuffer;

	RefCountPtr<RHIBuffer> mUboBuffer;

	RefCountPtr<RHITexture> mResultTexture;

	RefCountPtr<RHITexture> mColorTexture;

	RefCountPtr<RHITexture> mHdrTexture;

	RefCountPtr<RHISampler> mHdrSampler;

	RefCountPtr<RHITexture> mCacheTexture;

	RefCountPtr<AccelerationStructure> mTopLevelAS;



	ShaderPtr<RayTraceRgenShader> mRgenShader;

	ShaderPtr<RayTraceRchitShader> mRchitShader;

	ShaderPtr<RayTraceRmissShader> mRmissShader;

	ShaderPtr<HdrSampleRmissShader> mHdrMissShader;

	RefCountPtr<RHIDescriptor> mDescriptor;

	DescriptorMask mDescriptorMask;


	RefCountPtr<RayTracingPipeline> mPipeline;

};
